<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <script>
    async function fetchTest() {
      const headers = new Headers();

      headers.append('content-type', 'application/json');

      const url = `http://localhost:3000/register`;

      const response = await fetch(url, {
        method: 'post',
        headers: headers,
        body: JSON.stringify({
          username: 'itheima9876',
          password: '123456'
        })
      })

      const data = await response.json();

      console.log(data.data);
    }

    fetchTest();
  </script>
  <!-- <script>
    ; (async function () {
      const headers = new Headers();

      headers.append('content-type', 'application/json');

      const url = `http://hmajax.itheima.net/api/register`;

      // fetch(url, {
      //   method: 'post',
      //   headers: headers,
      //   body: JSON.stringify({
      //     username: 'itheima9876',
      //     password: '123456'
      //   })
      // }).then(res => {
      //   return res.json();
      // }).then(res2 => {
      //   console.log(res2);
      //   console.log(res2.data);
      //   console.log(res2.message);
      // }).catch(err => {
      //   console.log(33);
      // })

      try {
        const res = await fetch(url, {
          method: 'post',
          headers,
          body: JSON.stringify({
            username: 'itheima9876',
            password: '123456'
          })
        });

        const data = await res.json();

        console.log(data);
      } catch (err) {
        console.log(err);
      }
    })()
  </script> -->
</body>

</html>